package pl.edu.agh.bd2.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class Main {
	public static void main(String [] args){
		System.out.println("Hello hibernate");
		
		// Wczytujemy konfigurację hibernate
		SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
		// otwieramy sesję do bazy
		Session session = sessionFactory.openSession();
		
		Address address = new Address("Krakowska", 33, "Cracow","30-000", "Poland");
		Person person = new Person("Mietek", "Wozniak", 30, address);
		
		//zapisujemy
		session.beginTransaction();
		session.save(person);
		session.getTransaction().commit();
		
		//zmieniamy coś w obiekcie
		person.setAge(34);
		session.beginTransaction();
		session.saveOrUpdate(person);
		session.getTransaction().commit();
		
		
		session.close();
		
	}
}
